import { toast } from 'vue-sonner';
import { h } from 'vue';
import { CheckCircle, Info, AlertCircle, XCircle } from 'lucide-vue-next';

// Toast 类型定义
export type ToastType = 'success' | 'info' | 'warning' | 'error';

// Toast 配置接口
export interface ToastOptions {
  duration?: number;
  description?: string;
  action?: {
    label: string;
    onClick: () => void;
  };
}

// 默认配置
const defaultOptions = {
  duration: 2000,
};

// 成功提示
export function showSuccess(message: string, options?: ToastOptions) {
  return toast.success(message, {
    ...defaultOptions,
    ...options,
    icon: h(CheckCircle, { class: 'w-4 h-4 text-green-500' }),
    style: {
      background: 'var(--background)',
      border: '1px solid var(--border)',
      color: 'var(--foreground)',
    },
    class: 'border-green-200 bg-green-50 dark:bg-green-950 dark:border-green-800',
  });
}

// 信息提示
export function showInfo(message: string, options?: ToastOptions) {
  return toast.info(message, {
    ...defaultOptions,
    ...options,
    icon: h(Info, { class: 'w-4 h-4 text-blue-500' }),
    style: {
      background: 'var(--background)',
      border: '1px solid var(--border)',
      color: 'var(--foreground)',
    },
    class: 'border-blue-200 bg-blue-50 dark:bg-blue-950 dark:border-blue-800',
  });
}

// 警告提示
export function showWarning(message: string, options?: ToastOptions) {
  return toast.warning(message, {
    ...defaultOptions,
    ...options,
    icon: h(AlertCircle, { class: 'w-4 h-4 text-yellow-500' }),
    style: {
      background: 'var(--background)',
      border: '1px solid var(--border)',
      color: 'var(--foreground)',
    },
    class: 'border-yellow-200 bg-yellow-50 dark:bg-yellow-950 dark:border-yellow-800',
  });
}

// 错误提示
export function showError(message: string, options?: ToastOptions) {
  return toast.error(message, {
    ...defaultOptions,
    ...options,
    icon: h(XCircle, { class: 'w-4 h-4 text-red-500' }),
    style: {
      background: 'var(--background)',
      border: '1px solid var(--border)',
      color: 'var(--foreground)',
    },
    class: 'border-red-200 bg-red-50 dark:bg-red-950 dark:border-red-800',
  });
}

// 通用提示函数
export function showToast(type: ToastType, message: string, options?: ToastOptions) {
  switch (type) {
    case 'success':
      return showSuccess(message, options);
    case 'info':
      return showInfo(message, options);
    case 'warning':
      return showWarning(message, options);
    case 'error':
      return showError(message, options);
    default:
      return toast(message, {
        ...defaultOptions,
        ...options,
      });
  }
}

export { toast };
